import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Test {

    public static void main(String[] args) {
        try{
            int[] array = null;
            func();
            System.out.println(array[10]);
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("抛出了xxx异常...");
            e.printStackTrace();
        }
        // func();
        System.out.println("after try catch");
    }

    public static void func(){
        int[] array = {1,2,3};
        System.out.println(array[100]);
    }

    public static void func1() throws FileNotFoundException{
        FileInputStream fileInputStream = new FileInputStream("路径");

    }

    public static void main2(String[] args) {
        try {
            func1();
        }catch (FileNotFoundException e){

        }catch (NullPointerException e){

        }catch (Exception e){

        }finally {
            // 处理资源的关闭，防止资源浪费
        }

    }

    public static int getElement(int[] array, int index){
        if(index < 0 || index > array.length){
            throw new IndexOutOfBoundsException("传递的数组下标越界了");
        }

        if(array == null){
            throw new NullPointerException("传递的数组为null");
        }

        return array[index];
    }

    public static void main1(String[] args) {
        int[] array = {1,2,3};
        try {
            getElement(array, 3);
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("捕获了空指针异常");
        }catch (IndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("捕获了数组下标越界异常");
        }

        try {
            FileInputStream fileInputStream = new FileInputStream("路径");
        }catch (FileNotFoundException e){

        }
    }
}
